function test() {
    var arr = []
    for (var i = 0; i < 10; i++) {
        arr[i] = function () { console.log(i); }
    }
    return arr
}
var myArr = test()
for(let i=0;i<10;i++){
    myArr[i]()
}